/**
 * 
 * 版权所有：2015-麦田IT集团信息中心技术三部
 * 项目名称：wheat   
 * 类名称：cn.maitian.bss.quartz.action.ConfigQuartzAction     
 * 创建人：孔庆胜 
 * 创建时间：2015-6-23 上午11:53:45   
 * 修改人：
 * 修改时间：2015-6-23 上午11:53:45   
 * 修改备注：   
 * @version   V1.0
 */
package action;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import bean.ConfigQuartzJobs;
import job.SunEeeTask;
import model.CronTriggerModel;
import model.SimpleTriggerModel;
import org.quartz.CronExpression;
import org.quartz.CronTrigger;
import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.SimpleTrigger;
import org.quartz.Trigger;
import org.quartz.UnableToInterruptJobException;
import org.quartz.impl.StdScheduler;
import org.quartz.impl.StdSchedulerFactory;
import org.springframework.beans.BeansException;
import org.springframework.web.bind.annotation.PathVariable;
import util.SpringContext;


/**
 * 
* @Title: ConfigQuartzAction.java
* @Package cn.maitian.bss.quartz.action
* @Description: 定时任务动态执行
* @author 孔庆胜   
* @date 2015-6-23 下午12:00:14
* @version V1.0
 */
public class ConfigQuartzService {
	
	StdScheduler scheduler = (StdScheduler) SpringContext.getBean("quScheduler");
	ConfigQuartzJobs quartzJobs = (ConfigQuartzJobs)SpringContext.getBean("quartzJobs");

	private static SchedulerFactory gSchedulerFactory = new StdSchedulerFactory();

	private static String JOB_GROUP_NAME = "SUNEEE_JOBGROUP_NAME2";
	private static String TRIGGER_GROUP_NAME = "SUNEEE_TRIGGERGROUP_NAME2";
	/**
	 * 
	 * @Title: list
	 * @author 孔庆胜 
	 * @Description: 所有定时任务列表
	 * @return
	 * @throws SchedulerException
	 */
	public String list(){
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
		List<CronTriggerModel> cronList = new ArrayList<CronTriggerModel>();
		try {
			String[] triggerGroups;
	        String[] triggers;
	        triggerGroups = scheduler.getTriggerGroupNames();
	        for (int i = 0; i < triggerGroups.length; i++) {
	           triggers = scheduler.getTriggerNames(triggerGroups[i]);
	           for (int j = 0; j < triggers.length; j++) {
	              Trigger tg = scheduler.getTrigger(triggers[j], triggerGroups[i]);
	              if(tg instanceof CronTrigger){
	            	  JobDetail jobDetail = scheduler.getJobDetail(tg.getJobName(), tg.getJobGroup());
	            	  CronTriggerModel ctm = new CronTriggerModel();
	            	  ctm.setTriggerName(((CronTrigger)tg).getName());
	            	  ctm.setTriggerGroupName(((CronTrigger)tg).getGroup());
	            	  ctm.setJobName(((CronTrigger)tg).getJobName());
	            	  ctm.setJobGroupName(((CronTrigger)tg).getJobGroup());
	            	  ctm.setClassPath(jobDetail.getJobClass().getCanonicalName());
	            	  ctm.setCronExpression(((CronTrigger)tg).getCronExpression());
	            	  ctm.setStartTime(format.format(((CronTrigger)tg).getStartTime()));
	            	  ctm.setNextFireTime(format.format(((CronTrigger)tg).getNextFireTime()));
	            	  ctm.setPriority(((CronTrigger)tg).getPriority());
	            	  ctm.setDescription(((CronTrigger)tg).getDescription());
	            	  if(scheduler.getTriggerState(tg.getName(), tg.getGroup())==Trigger.STATE_NORMAL){
	            		  ctm.setState("正常");
	            	  }else if(scheduler.getTriggerState(tg.getName(), tg.getGroup())== Trigger.STATE_PAUSED){
	            		  ctm.setState("暂停");
	            	  }else if(scheduler.getTriggerState(tg.getName(), tg.getGroup())== Trigger.STATE_COMPLETE){
	            		  ctm.setState("已完成");
	            	  }else if(scheduler.getTriggerState(tg.getName(), tg.getGroup())== Trigger.STATE_ERROR){
	            		  ctm.setState("错误");
	            	  }else if(scheduler.getTriggerState(tg.getName(), tg.getGroup())== Trigger.STATE_BLOCKED){
	            		  ctm.setState("锁定");
	            	  }else if(scheduler.getTriggerState(tg.getName(), tg.getGroup())== Trigger.STATE_NONE){
	            		  ctm.setState("无状态");
	            	  }
	            	  cronList.add(ctm);
	              }
	           }
	        }
		} catch (BeansException e) {
			e.printStackTrace();
		} catch (SchedulerException e) {
			e.printStackTrace();
		}
		
		return "list";
	}
	/**
	 * 
	 * @Title: simpList
	 * @author 孔庆胜 
	 * @Description:循环任务列表
	 * @date: 2015-6-25 下午6:24:25
	 * @return
	 */
	public String simpList(){
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		List<SimpleTriggerModel> simpList = new ArrayList<SimpleTriggerModel>();
		try {
			String[] triggerGroups;
	        String[] triggers;
	        triggerGroups = scheduler.getTriggerGroupNames();
	        for (int i = 0; i < triggerGroups.length; i++) {
	           triggers = scheduler.getTriggerNames(triggerGroups[i]);
	           for (int j = 0; j < triggers.length; j++) {
	              Trigger tg = scheduler.getTrigger(triggers[j], triggerGroups[i]);
	              if (tg instanceof SimpleTrigger) {
	            	  JobDetail jobDetail = scheduler.getJobDetail(tg.getJobName(), tg.getJobGroup());
	            	  SimpleTriggerModel sim = new SimpleTriggerModel();
	            	  sim.setTriggerName(((SimpleTrigger)tg).getName());
	            	  sim.setTriggerGroupName(((SimpleTrigger)tg).getGroup());
	            	  sim.setJobName(((SimpleTrigger)tg).getJobName());
	            	  sim.setJobGroupName(((SimpleTrigger)tg).getJobGroup());
	            	  sim.setRepeatInterval(((SimpleTrigger)tg).getRepeatInterval());
	            	  sim.setRepeatCount(((SimpleTrigger)tg).getRepeatCount());
	            	  sim.setStartTime(format.format(((SimpleTrigger)tg).getStartTime()));
	            	  sim.setNextFireTime(((SimpleTrigger)tg).getNextFireTime()==null?"无":format.
	            			  format(((SimpleTrigger)tg).getNextFireTime()));
	            	  sim.setPriority(((SimpleTrigger)tg).getPriority());
	            	  sim.setDescription(((SimpleTrigger)tg).getDescription());
	            	  sim.setClassPath(jobDetail.getJobClass().getCanonicalName());
	            	  sim.setTimesTriggered(((SimpleTrigger)tg).getTimesTriggered());
	            	  if(scheduler.getTriggerState(tg.getName(), tg.getGroup())==Trigger.STATE_NORMAL){
	            		  sim.setState("正常");
	            	  }else if(scheduler.getTriggerState(tg.getName(), tg.getGroup())== Trigger.STATE_PAUSED){
	            		  sim.setState("暂停");
	            	  }else if(scheduler.getTriggerState(tg.getName(), tg.getGroup())== Trigger.STATE_COMPLETE){
	            		  sim.setState("已完成");
	            	  }else if(scheduler.getTriggerState(tg.getName(), tg.getGroup())== Trigger.STATE_ERROR){
	            		  sim.setState("错误");
	            	  }else if(scheduler.getTriggerState(tg.getName(), tg.getGroup())== Trigger.STATE_BLOCKED){
	            		  sim.setState("锁定");
	            	  }else if(scheduler.getTriggerState(tg.getName(), tg.getGroup())== Trigger.STATE_NONE){
	            		  sim.setState("无状态");
	            	  }
	            	  simpList.add(sim);
	              }
	           }
	        }
		} catch (BeansException e) {
			e.printStackTrace();
		} catch (SchedulerException e) {
			e.printStackTrace();
		}
		return "simpList";
	}
	
	/**
	 * 
	 * @Title: toAdd
	 * @author 孔庆胜 
	 * @Description:跳转到添加页面
	 * @date: 2015-6-24 下午4:35:33
	 * @return
	 */
	public String toAdd(){
		List<String> jobList = quartzJobs.getJobsList();
		return "toAdd";
	}
	/**
	 * 
	 * @Title: add
	 * @author 孔庆胜 
	 * @Description: 定时任务添加
	 * @param jobName
	 * @param jobGroupName
	 * @param triggerName
	 * @param triggerGroupName
	 * @param time
	 * @param priority
	 * @param description
	 * @return
	 */
    public String add(@PathVariable(value = "jobName")String jobName, 
    		          @PathVariable(value = "jobGroupName")String jobGroupName, 
    		          @PathVariable(value = "triggerName")String triggerName, 
    		          @PathVariable(value = "triggerGroupName")String triggerGroupName,
    		          @PathVariable(value = "time")String time,
    		          @PathVariable(value = "priority")String priority,
    		          @PathVariable(value = "description")String description,
    		          @PathVariable(value = "classPath")String classPath){
    	try {
    		if(jobName == null || jobGroupName == null || triggerName == null || triggerGroupName == null
					|| time == null || priority == null || description == null || classPath == null
					|| "".equals(jobName) || "".equals(triggerName) || "".equals(time) 
					|| "".equals(classPath)){
				return "reAdd";
			}
			
    		Class<?> jobClass = Class.forName(classPath);
			JobDetail jobDetail = new JobDetail(jobName, 
					jobGroupName.equals("")?"DefultCronJobGroup":jobGroupName, jobClass);
			CronTrigger cronTrigger = new CronTrigger(triggerName, 
					triggerGroupName.equals("")?"DefultCronTriggerGroup":triggerGroupName);
			CronExpression cexp = new CronExpression(time);
			cronTrigger.setCronExpression(cexp);
			cronTrigger.setPriority(priority.equals("")?5:Integer.parseInt(priority));
			cronTrigger.setDescription(description);
			scheduler.scheduleJob(jobDetail, cronTrigger);
		} catch (NumberFormatException e) {
			return "reAdd";
		} catch (ParseException e) {
			return "reAdd";
		} catch (SchedulerException e) {
			return "reAdd";
		} catch (ClassNotFoundException e) {
			return "reAdd";
		}
    	
		return "add";
	}
    
    /**
     * 
     * @Title: simpAdd
     * @author 孔庆胜 
     * @Description: 添加次数定时任务
     * @date: 2015-6-25 上午11:39:28
     * @param jobName
     * @param jobGroupName
     * @param triggerName
     * @param triggerGroupName
     * @param repeatInterval
     * @param repeatCount
     * @param priority
     * @param description
     * @param classPath
     * @return
     */
    public String simpAdd(@PathVariable(value = "jobName")String jobName, 
				          @PathVariable(value = "jobGroupName")String jobGroupName, 
				          @PathVariable(value = "triggerName")String triggerName, 
				          @PathVariable(value = "triggerGroupName")String triggerGroupName,
				          @PathVariable(value = "repeatInterval")String repeatInterval,
				          @PathVariable(value = "repeatCount")String repeatCount,
				          @PathVariable(value = "priority")String priority,
				          @PathVariable(value = "description")String description,
				          @PathVariable(value = "classPath")String classPath){
    	if(jobName == null || jobGroupName == null || triggerName == null || triggerGroupName == null
				|| repeatInterval == null || priority == null || description == null || classPath == null
				|| repeatCount == null || "".equals(jobName) || "".equals(triggerName) 
				|| "".equals(repeatInterval) || "".equals(classPath) || "".equals(repeatCount)){
			return "reAdd";
		}
    	try {
			Class<?> jobClass = Class.forName(classPath);
			JobDetail jobDetail = new JobDetail(jobName, 
					jobGroupName.equals("")?"DefultSimpleJobGroup":jobGroupName, jobClass);
			SimpleTrigger simpleTrigger = new SimpleTrigger(triggerName, 
					triggerGroupName.equals("")?"DefultSimpleTriggerGroup":triggerGroupName);
			if(Long.parseLong(repeatInterval) < 1){
				return "reAdd";
			}
			if(Integer.parseInt(repeatCount) < 1){
				return "reAdd";
			}
			simpleTrigger.setStartTime(new Date());
			simpleTrigger.setRepeatInterval(Long.parseLong(repeatInterval));
			simpleTrigger.setRepeatCount(Integer.parseInt(repeatCount));
			simpleTrigger.setPriority(priority.equals("")?5:Integer.parseInt(priority));
			simpleTrigger.setDescription(description);
			scheduler.scheduleJob(jobDetail, simpleTrigger);
		} catch (NumberFormatException e) {
			return "reAdd";
		} catch (ClassNotFoundException e) {
			return "reAdd";
		} catch (SchedulerException e) {
			return "reAdd";
		}
    	return "simpAdd";
    }
	
    /**
     * 
     * @Title: toEdit
     * @author 孔庆胜 
     * @Description: 跳转修改页面
     * @date: 2015-6-25 上午11:39:04
     * @param triggerName
     * @param triggerGroupName
     * @return
     */
    public String toEdit(@PathVariable(value = "tName")String triggerName, 
                         @PathVariable(value = "tgName")String triggerGroupName){
    	try {
			Trigger trigger = (Trigger)scheduler.getTrigger(triggerName, triggerGroupName);
			if(trigger == null){
				return "add";
			}
			JobDetail jobDetail = scheduler.getJobDetail(trigger.getJobName(), trigger.getJobGroup());
			if(trigger instanceof CronTrigger){
				CronTrigger cronTrigger = (CronTrigger)trigger;
				CronTriggerModel ctm = new CronTriggerModel();
				ctm.setJobName(cronTrigger.getJobName());
				ctm.setJobGroupName(cronTrigger.getJobGroup());
				ctm.setTriggerName(triggerName);
				ctm.setTriggerGroupName(triggerGroupName);
				ctm.setCronExpression(cronTrigger.getCronExpression());
				ctm.setPriority(cronTrigger.getPriority());
				ctm.setDescription(cronTrigger.getDescription());
				ctm.setClassPath(jobDetail.getJobClass().getCanonicalName());
			}else if(trigger instanceof SimpleTrigger){
				SimpleTrigger simpleTrigger = (SimpleTrigger)trigger;
				SimpleTriggerModel stm = new SimpleTriggerModel();
				stm.setJobName(simpleTrigger.getJobName());
				stm.setJobGroupName(simpleTrigger.getJobGroup());
				stm.setTriggerName(triggerName);
				stm.setTriggerGroupName(triggerGroupName);
				stm.setRepeatInterval(simpleTrigger.getRepeatInterval());
				stm.setRepeatCount(simpleTrigger.getRepeatCount());
				stm.setPriority(simpleTrigger.getPriority());
				stm.setDescription(simpleTrigger.getDescription());
				stm.setClassPath(jobDetail.getJobClass().getCanonicalName());
				return "toSimpleEdit";
			}
		} catch (SchedulerException e) {
			return "add";
		}
		
    	return "toEdit";
    }
    /**
     * 
     * @Title: edit
     * @author 孔庆胜 
     * @Description: 定时任务修改
     * @param triggerName
     * @param triggerGroupName
     * @param time
     * @param priority
     * @param description
     * @return
     */
    public String edit(@PathVariable(value = "triggerName")String triggerName, 
    		           @PathVariable(value = "triggerGroupName")String triggerGroupName,
    		           @PathVariable(value = "time")String time,
    		           @PathVariable(value = "priority")String priority,
    		           @PathVariable(value = "description")String description) {
		try {
			if(null == triggerName || null == triggerGroupName || null == time || null == priority 
					|| "".equals(time) || null == description || "".equals(triggerName) 
					|| "".equals(triggerGroupName)){
				return "edit";
			}
			CronTrigger cronTrigger = (CronTrigger)scheduler.getTrigger(triggerName, triggerGroupName);
			if(cronTrigger == null){
				return "edit";
			}
			
			if(!"".equals(time)){
				CronExpression cexp = new CronExpression(time);
				cronTrigger.setCronExpression(cexp);
			}
			if(!"".equals(priority)){
				cronTrigger.setPriority(Integer.parseInt(priority));
			}
			cronTrigger.setDescription(description);
			scheduler.rescheduleJob(triggerName, triggerGroupName, cronTrigger);
		} catch (NumberFormatException e) {
		} catch (SchedulerException e) {
		} catch (ParseException e) {
		}
		return "edit";
	}
    
    public String simpEdit(@PathVariable(value = "triggerName")String triggerName, 
				           @PathVariable(value = "triggerGroupName")String triggerGroupName,
				           @PathVariable(value = "repeatInterval")String repeatInterval,
				           @PathVariable(value = "repeatCount")String repeatCount,
				           @PathVariable(value = "priority")String priority,
				           @PathVariable(value = "description")String description){
    	if(null == triggerName || null == triggerGroupName || null == repeatInterval || null == priority 
				|| null == description || null == repeatCount || "".equals(triggerName) 
				|| "".equals(triggerGroupName) || "".equals(repeatInterval) || "".equals(repeatCount)){
			return "simpAdd";
		}
    	try {
			SimpleTrigger simpTrigger = (SimpleTrigger)scheduler.getTrigger(triggerName, triggerGroupName);
			if(simpTrigger == null){
				return "simpAdd";
			}
			if(!"".equals(repeatInterval)){
				if(Long.parseLong(repeatInterval) < 1){
					return "simpAdd";
				}
				simpTrigger.setRepeatInterval(Long.parseLong(repeatInterval));
			}
			if(!"".equals(repeatCount)){
				if(Integer.parseInt(repeatCount) < 1){
					return "simpAdd";
				}
				simpTrigger.setRepeatCount(Integer.parseInt(repeatCount));
			}
			if(!"".equals(priority)){
				simpTrigger.setPriority(Integer.parseInt(priority));
			}
			simpTrigger.setDescription(description);
			scheduler.rescheduleJob(triggerName, triggerGroupName, simpTrigger);
    	} catch (NumberFormatException e) {
		} catch (SchedulerException e) {
		}
    	return "simpAdd";
    }
    
    /**
     * 
     * @Title: delete
     * @author 孔庆胜 
     * @Description: 定时任务删除
     * @param triggerName
     * @param triggerGroupName
     * @return
     */
	public String delete(@PathVariable(value = "tName")String triggerName, 
			             @PathVariable(value = "tgName")String triggerGroupName) {
		int state = 0;
		try {
			Trigger trigger = scheduler.getTrigger(triggerName, triggerGroupName);
			if(trigger == null){
				return "delete";
			}
			if(trigger instanceof CronTrigger){
				state = 1;
			}else if(trigger instanceof SimpleTrigger){
				state = 2;
			}
			scheduler.pauseTrigger(triggerName, triggerGroupName);// 停止触发器
			scheduler.unscheduleJob(triggerName, triggerGroupName);// 移除触发器
			scheduler.deleteJob(trigger.getJobName(), trigger.getJobGroup());// 删除任务
		} catch (SchedulerException e) {
		}
		if(state == 2){
			return "simpAdd";
		}
		return "delete";
	}

	/**
	 * 
	 * @Title: replay
	 * @author 孔庆胜 
	 * @Description: 定时任务恢复执行
	 * @param triggerName
	 * @param triggerGroupName
	 * @return
	 */
	public String replay(@PathVariable(value = "tName")String triggerName, 
			             @PathVariable(value = "tgName")String triggerGroupName){
		Trigger trigger = null;
		try {
			trigger = scheduler.getTrigger(triggerName, triggerGroupName);
			if(trigger == null){
				return "replay";
			}
			scheduler.resumeTrigger(triggerName, triggerGroupName);
			
		} catch (SchedulerException e) {
		}
		if(trigger instanceof SimpleTrigger){
			return "simpAdd";
		}
		return "replay";
	}
	
	/**
	 * 
	 * @Title: pause
	 * @author 孔庆胜 
	 * @Description: 定时任务暂停
	 * @param triggerName
	 * @param triggerGroupName
	 * @return
	 */
    public String pause(@PathVariable(value = "tName")String triggerName, 
    		            @PathVariable(value = "tgName")String triggerGroupName){
    	Trigger trigger = null;
    	try {
			trigger = scheduler.getTrigger(triggerName, triggerGroupName);
			if(trigger == null){
				return "pause";
			}
			scheduler.pauseTrigger(triggerName, triggerGroupName);
			
		} catch (SchedulerException e) {
		}
    	if(trigger instanceof SimpleTrigger){
			return "simpAdd";
		}
		return "pause";
	}
    
    /**
     * 
     * @Title: atOnceRun
     * @author 孔庆胜 
     * @Description: 定时任务手动执行一次
     * @param triggerName
     * @param triggerGroupName
     * @return
     */
    public String atOnceRun(@PathVariable(value = "tName")String triggerName, 
    		                @PathVariable(value = "tgName")String triggerGroupName){
    	Trigger trigger = null;
    	try {
			trigger = scheduler.getTrigger(triggerName, triggerGroupName);
			if(trigger == null){
				return "pause";
			}
			scheduler.triggerJob(trigger.getJobName(), trigger.getJobGroup());
			
		} catch (SchedulerException e) {
		}
    	if(trigger instanceof SimpleTrigger){
			return "simpAdd";
		}
    	return "atOnce";
    }
    
    /**
     * 
     * @Title: runList
     * @author 孔庆胜 
     * @Description: 查询正在执行的任务列表
     * @return
     */
    @SuppressWarnings("unchecked")
	public String runList(){
    	SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
		List<JobExecutionContext> executingJobs = scheduler.getCurrentlyExecutingJobs();
    	List<CronTriggerModel> jobList = new ArrayList<CronTriggerModel>(executingJobs.size());
    	for (JobExecutionContext executingJob : executingJobs) {
    		CronTriggerModel job = new CronTriggerModel();
    	    Trigger trigger = executingJob.getTrigger();
    	    JobDetail jobDetail = executingJob.getJobDetail();
    	    job.setJobName(trigger.getJobName());
    	    job.setJobGroupName(trigger.getJobGroup());
    	    job.setTriggerName(trigger.getName());
    	    job.setTriggerGroupName(trigger.getGroup());
    	    job.setStartTime(format.format(executingJob.getFireTime()));
    	    job.setNextFireTime(trigger.getNextFireTime()==null?"无":format.format(trigger.getNextFireTime()));
    	    job.setPriority(trigger.getPriority());
    	    job.setDescription(trigger.getDescription());
    	    Class<?>[] faceGroup = (jobDetail.getJobClass()).getInterfaces();
			for(int i=0; i<faceGroup.length; i++){
				if((faceGroup[i].getSimpleName()).equals("InterruptableJob")){
					job.setImplInte(true);
					break;
				}
			}
    	    jobList.add(job);
    	}
    	return "runlist";
    }
    
    /**
     * @Title: interruptJob
     * @Description:中断正在执行的定时任务
     * @param triggerName
     * @param triggerGroupName
     * @return
     */
    public String interruptJob(@PathVariable(value = "tName")String triggerName, 
                               @PathVariable(value = "tgName")String triggerGroupName){
    	try {
			Trigger trigger = scheduler.getTrigger(triggerName, triggerGroupName);
			if(trigger == null){
				return "interrupt";
			}
			scheduler.interrupt(trigger.getJobName(), trigger.getJobGroup());
		} catch (UnableToInterruptJobException e) {
		} catch (SchedulerException e) {
		}
    	return "interrupt";
    }


	public static void addJob(String jobName, Class cls, String time) {
		try {
			Scheduler sched = gSchedulerFactory.getScheduler();
			JobDetail jobDetail = new JobDetail(jobName, JOB_GROUP_NAME, cls);// 任务名，任务组，任务执行类
			// 触发器
			CronTrigger trigger = new CronTrigger(jobName, TRIGGER_GROUP_NAME);// 触发器名,触发器组
			trigger.setCronExpression(time);// 触发器时间设定
			sched.scheduleJob(jobDetail, trigger);
			// 启动
			if (!sched.isShutdown()) {
				sched.start();
			}
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	public static void addJob(String jobName, String jobGroupName,
							  String triggerName, String triggerGroupName, Class jobClass,
							  String time) {
		try {
			Scheduler sched = gSchedulerFactory.getScheduler();
			JobDetail jobDetail = new JobDetail(jobName, jobGroupName, jobClass);// 任务名，任务组，任务执行类
			// 触发器
			CronTrigger trigger = new CronTrigger(triggerName, triggerGroupName);// 触发器名,触发器组
			trigger.setCronExpression(time);// 触发器时间设定
			sched.scheduleJob(jobDetail, trigger);
			// 启动
			if (!sched.isShutdown()) {
				sched.start();
			}
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	public static void main(String[] args) {

//		ConfigQuartzService.addJob("SunEEE定时任务", SunEeeTask.class,"0/1 * * * * ?");
//		ConfigQuartzService.addJob("SunEEE定时任务",SunEeeTask.class,"0/1 * * * * ?","X","Y");
		ConfigQuartzService.addJob("SunEEE定时任务","X","Y","Z",SunEeeTask.class,"0/1 * * * * ?");

	}
}
